<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="shareLinkConfig-form">
    <div class="layui-form-item" style="display: none">
        <label class="layui-form-label required">id</label>
        <div class="layui-input-block">
            <input type="text" name="id" lay-verify="required" lay-reqtext="Id不能为空"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">工单号(只读)</label>
        <div class="layui-input-block">
            <input type="text" name="taskNumber" lay-verify="required" lay-reqtext="工单号不能为空" readonly
                   value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">测评名称(只读)</label>
        <div class="layui-input-block">
            <input type="text" name="subject" lay-verify="required" lay-reqtext="工单号不能为空" readonly
                   value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">发起人编号(只读)</label>
        <div class="layui-input-block">
            <input type="text" name="initiatorId" lay-verify="required" readonly lay-reqtext="测评发起人id不能为空"
                   value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">发起人昵称(只读)</label>
        <div class="layui-input-block">
            <input type="text" name="initiatorName" lay-verify="required" readonly lay-reqtext="测评发起人昵称不能为空"
                   value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">测评结束时间</label>
        <div class="layui-input-block">
            <input type="text" name="endTime" id="endTime" lay-verify="required" lay-reqtext="测评结束时间不能为空"
                   value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">提交报告周期/天</label>
        <div class="layui-input-block">
            <input type="text" name="limitDays" lay-verify="required" lay-reqtext="测评报告周期(天)不能为空"
                   placeholder="请输入提交报告周期"
                   value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" id="saveBtn" lay-submit lay-filter="saveBtn">确认修改</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script src="../../lib/common/permissions.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script>

    window.onload = function () {
        /**
         * 权限判断
         * */
        const btnRoles = {
            "saveBtn": 'Platform Activities Specialist,Platform Activities Leader',
        }
        buttonPermissions(btnRoles)
    }

    /**
     *
     * "limitDays": "2",
     * "createTime": "2023-05-22 20:23:45",
     * "subject": " X5N-咔咔码一次性压缩毛巾(4M2)",
     * "initiatorName": "想养一只叫十三的猫",
     * "initiatorId": "0726100819888266",
     * "endTime": "2023-05-31",
     * "id": "1660622255257948160",
     * "taskNumber": "PC230522082345478545"
     * @type {{}}
     */
    let paramData = {};

    //子窗口接受参数
    function childParam(taskData) {
        if (!isNotNull(taskData.id)) {
            layer.msg('数据异常');
            setTimeout(function () {
                let iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
            }, 1500);
        }
        paramData = taskData;
        // 初始化表单
        init()
    }


    function init() {
        layui.use(['form', 'laydate'], function () {
            let form = layui.form,
                laydate = layui.laydate;
            form.val('shareLinkConfig-form', {
                "limitDays": paramData.limitDays,
                "createTime": paramData.createTime,
                "subject": paramData.subject,
                "initiatorName": paramData.initiatorName,
                "initiatorId": paramData.initiatorId,
                "endTime": paramData.endTime,
                "id": paramData.id,
                "taskNumber": paramData.taskNumber,
            });
            // 初始化日期选择器
            laydate.render({
                elem: '#endTime',
                type: 'date', //选择器类型，只显示年月
                format: 'yyyy-MM-dd', //日期格式
                min: paramData.createTime
            });

        })
    }

    layui.use(['layer', 'form', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("确定提交吗？", {
                title: '提示'
            }, function () {
                let myMsg = layer.msg("正在提交...", {
                    icon: 16,
                    time: -1
                })
                $.ajax({
                    type: "post",
                    url: '/trialEvaluation/update/evaluation/task',
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    contentType: 'application/json; charset=UTF-8',
                    success: function (req) {
                        if (req.code === '200') {
                            layer.msg("操作成功");
                            layer.close(index);
                            // 关闭弹出层
                            setTimeout(function () {
                                layer.close(myMsg);//手动关闭
                                let iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                // 调用父页面的方法
                                let parentWindow = window.parent;
                                parentWindow.reloadTable();
                            }, 1500);
                        } else {
                            layer.msg(req.msg);
                        }

                    },
                    error: function (e) {
                        layer.msg("操作失败");
                        layer.close(myMsg);//手动关闭
                    }
                })

            });
            return false;
        });

    });
</script>
</body>
</html>
